package pers.cj.pdos.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import pers.cj.pdos.entity.BudgetProject;
import pers.cj.pdos.entity.Custom;
import pers.cj.pdos.mapper.BudgetProjectMapper;
import pers.cj.pdos.service.IBudgetProjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pers.cj.pdos.utils.Utils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenj
 * @since 2019-11-04
 */
@Service
public class BudgetProjectServiceImpl extends ServiceImpl<BudgetProjectMapper, BudgetProject> implements IBudgetProjectService {
    @Autowired
    BudgetProjectMapper budgetProjectMapper;
    @Override
    public List<BudgetProject> listPage(String companyId, Integer page, Integer limit, Integer type, String search) {
        return budgetProjectMapper.listVo(companyId,Utils.genPage(page,limit),limit,type, Utils.genLikeData(search));
    }

    @Override
    public long count(String companyId, Integer type, String search) {
        if (type !=null){
            if (type == 1) {
                type = 1;
            } else {
                type = 2;
            }
        }
        return budgetProjectMapper.count(companyId,type, Utils.genLikeData(search));
    }

    @Override
    public boolean checkName(String name, String companyId) {
        return budgetProjectMapper.selectCount(new QueryWrapper<BudgetProject>().eq("company_id",companyId).eq("name",name)) > 0;
    }
}
